/**
 * Copyright 2010 Victor Egea Hernando
 *
 * RockScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * 
 * RockScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with RockScript.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef BATCH_H_
#define BATCH_H_

#include <string>
#include <iostream>

#include <rock/rock.h>
#include <paper/paper.h>

class batch_handler : public rock::parser_error_hnd, public paper::vmachine_hnd
{

public:
    /*------------------------------------------------------------------
       constructor
      ------------------------------------------------------------------*/
    batch_handler(){
		derr = serr = false;
    }
    /*------------------------------------------------------------------
       error handlers
      ------------------------------------------------------------------*/
    // process errors from the lexer & parser
    virtual void parserError( corelib::uint32 line, const corelib::ustring &error  )
    {
        std::cout << "error: " << line << ": " << rock::parser::unmangleMNames( error ) << std::endl;
		serr = true;
    }

    // process errors from the virtual machine
    virtual void dynError( const paper::vm_error &e )
    {
        std::cout << "error<routine " << e.rid << "> " << e.vmclass << "::" << rock::parser::unmangleMNames( e.method );
		std::cout << " -> " << rock::parser::unmangleMNames( e.error ) << std::endl;
		derr = true;
    }

public:
    // dynamic & static error
    bool derr, serr;

};

class batch
{

protected:
    // 
    batch();
    // 
    virtual ~batch();
    //
    corelib::int32 parse( const std::string &main_argument, const std::string &file );
    // 
    void debug( const std::string &class_name );
    // 
    void printDebugHelp( void );
    // 
    void printHelp( void );

public:
    // 
    int main( int argc, char *argv[] );
    //
    static batch &get(void);

protected:
    // batch flags
    corelib::uint32 flags_;

    // parser, compiler & virtual machine
    paper::vmachine vm;
    rock::parser parser;
    batch_handler hnd;

	// argument vector
    std::vector<std::string> args_;

    // singleton's instance
    static batch* instance_;

protected:
    // batch flags
    static const corelib::uint32 DEBUGGING = 1;
    static const corelib::uint32 DISSAMBLING = 2;

};

#endif // BATCH_H_

